vhdl 您所在的位置:网站首页 vhdl signed vhdl

vhdl

#vhdl| 来源: 网络整理| 查看: 265

VHDL can print any sort of text strings and also read and write files (using STD.TEXTIO) with that text. It can convert data from one format to another using built in attributes of types or signals and through utility funcitons.

E.g. You can also define your own functions for formatting that returns characters and strings. Some standard library functions are provided for this too. Examples of this at the bottom.

Strings concatenate just like signals using & (ampersand)

... signal x : std_logic_vector; begin --Some examples.... report integer'image(conv_integer(unsigned(x), x'length)) severity note; --or report std_logic_vector'image(x); --or report "0x" & to_hstring(x); ...

For a more complete example, take this excerpt from https://github.com/the-moog/vhdl_modular_blocks/blob/master/utils.vhd that I wrote some years ago.

library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; package utils is --! @brief Return the N'th nibble (4 bits) of a std_logic_vector as a hex digit in ASCII function to_hex(v : std_logic_vector; nibble : integer) return character; --! @brief Return a std_logic_vector representation of the ASCII position of a character function char2byte(c : in character) return std_logic_vector; --! @brief Convert a string into an arbitrary length std_logic_vector of string'length * 8 procedure str2bitstring(s : string; signal v : out std_logic_vector); --! @brief Return a new string with all the characters of the supplied string in upper case function ucase(v : string) return string; --! @brief Return a new string with all the characters of the supplied string in lower case function lcase(v : string) return string; --! @brief Return the supplied character mapped to upper case function ucase(c : character) return character; --! @brief Return the supplied character mapped to lower case function lcase(c : character) return character; --! @brief Pad a short string to n characters length with a given character function pads(constant s : string; length : positive; padchar:character:=' ') return string; --! @brief Returns a new string with a given character replaced function str_replace_char(constant s : string; constant find : character; constant replace : character) return string; --! @brief Limit strings to 0..9 and A..Z with underscore function str_simplify(constant s : string) return string; end package; package body utils is function pads(constant s : string; length : positive; padchar:character:=' ') return string is variable temp : string(1 to length); begin if length > s'length then temp(1 to s'length) := s; temp(s'length + 1 to length) := (others => padchar); else temp := s(1 to length); end if; return temp; end function; function str_replace_char(constant s : string; constant find : character; constant replace : character) return string is variable temp : string(s'range); begin for n in s'range loop if s(n) /= find then temp(n) := s(n); else temp(n) := replace; end if; end loop; return temp; end function; function str_simplify(constant s : string) return string is variable temp : string(s'range); variable us : unsigned(7 downto 0); begin for n in temp'range loop temp(n) := ucase(s(n)); us := conv_unsigned(character'pos(temp(n)), us'length); if not ((us >= character'pos('A') and us = character'pos('0') and us


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有